package hc.bre.data.strategy

import hc.bre.cmn.IDataDefOption
import hc.bre.cmn.IListOption
import hc.bre.cmn.ListOption
import hc.bre.cmn.RuleScriptBuilder

@groovy.transform.CompileStatic
class StrategyBuilder extends RuleScriptBuilder<StrategyDefinition>{
	@Override
	public void buildClassMemberClass() {
		apdInnerClass('ValueMap'){ IDataDefOption it ->
			ruleDef.valueDefList.each {
				apdNl("${it.declarationOfData()}")
			}
		}

		apdInnerClass('UserOption',ListOption.class){
			apdNl("ValueMap valueMap;")
		}
	};

	@Override
	public void buildClassMemberVariable() {
		ruleDef.list.each {
			apdNl("public static final UserOption ${it.code} = new UserOption(")
			apd("id:${it.id}, code:${referText(it.code)}, name:${referText(it.name)}, valueMap:new ValueMap(");
			String args = ruleDef.valueDefList.collect{itt->"${itt.code}:${referData(it.valueMap.get(itt.code),itt.type)}"}.join(",")
			apd(args);
			apd("));");
		}
	}

	@Override
	public void buildClassRule() {
	}
}
